﻿using duia.Canteenpay.Application.AppService;
using duia.Canteenpay.Domain.DomainObject;
using duia.Canteenpay.ViewModel;
using duia.Canteenpay.ViewModel.Users;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace duia.Canteenpay.WebApi.Controllers
{
    /// <summary>
    /// 用户管理
    /// </summary>
    public class UserController : BaseApiController
    {

        private readonly UsersAppService _usersAppService;

        public UserController(UsersAppService usersAppService)
        {
            _usersAppService = usersAppService;
        }

        /// <summary>
        /// 获取系统用户列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("{keyId}")]
        [ProducesResponseType(typeof(UserModelResponse), 200)]
        public async Task<UserModelResponse> Get(Guid keyId)
        {
            return await _usersAppService.Querys.Find(keyId);
        }

        /// <summary>
        /// 分页查询系统用户列表
        /// </summary>
        /// <param name="parame"></param>
        /// <returns></returns>
        [HttpPost, Route("page-user")]
        [ProducesResponseType(typeof(BasePageResponse<UserModelResponse>), 200)]
        public async Task<BasePageResponse<UserModelResponse>> Get([FromBody] SearchPageUserRequest parame)
        {
            return await _usersAppService.Querys.FindPageUser(parame);
        }

        /// <summary>
        /// 新增管理账号
        /// </summary>
        /// <param name="parame"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> Post([FromBody] AddUsersModelReceive parame)
        {
            return await _usersAppService.AddAsync(parame);
        }

        /// <summary>
        /// 修改管理账号信息
        /// </summary>
        /// <param name="keyId"></param>
        /// <param name="parame"></param>
        /// <returns></returns>
        [HttpPut]
        [ProducesResponseType(typeof(ApiResult<bool>), 200)]
        public async Task<bool> Put([FromBody] ModifyUsersModelRequest parame)
        {
            return await _usersAppService.ModifyAsync(parame);
        }

        /// <summary>
        /// 删除系统管理用户
        /// </summary>
        /// <param name="keyId"></param>
        /// <returns></returns>
        [HttpDelete("{keyId}")]
        [ProducesResponseType(typeof(ApiResult<Users>), 200)]
        public async Task<int> Delete(Guid keyId)
        {
            return await _usersAppService.RemoveAsync(keyId);
        }
    }
}
